package system.student.funtion.context;

import system.student.entity.updatepassword.UpdatePasswordRequest;
import system.student.entity.updatepassword.UpdatePasswordState;
import system.student.login.UpdatePasswordStrategy;
import system.student.login.impl.UseEmailUpdate;
import system.student.login.impl.UsePasswordUpdate;
import system.student.login.impl.UsePhoneUpdate;

import java.util.HashMap;

public class UpdatePasswordContext {
    private static final HashMap<UpdatePasswordState, UpdatePasswordStrategy> map = new HashMap<>();
    static {
        map.put(UpdatePasswordState.Password, new UsePasswordUpdate());
        map.put(UpdatePasswordState.Phone, new UsePhoneUpdate());
        map.put(UpdatePasswordState.Email, new UseEmailUpdate());
    }
    public void updatePassword(UpdatePasswordRequest request) {
        UpdatePasswordState state = request.getUpdatePasswordState();
        UpdatePasswordStrategy strategy = map.get(state);
        if (strategy != null) {
            strategy.updatePassword(request);
        }else {
            System.out.println("暂不支持该功能");
        }
    }
}
